package com.lsk.division.controller;

import com.lsk.division.MyService;
import com.lsk.division.entity.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.cache.annotation.Cacheable;


@RestController
@CrossOrigin(origins="*")
@RequestMapping("division")
@Api(value= "行政区划API" ,tags = "行政区划API")

public class MyController {

    @Autowired
    private MyService service;


    //查询全国所有省份
    @GetMapping("/findAllProvince")
    @ApiOperation("查询全国所有省份")
    @Cacheable(value = "china" )
    public Result findAllProvince(){
        return service.findAllProvince();
    }
    //查询所有县级的所有村级
    @Cacheable(value = "area")
    @GetMapping("/findAllVillageByAreaCode/{code}")
    @ApiOperation("根据县区编号查询所有村级区域(递归)")
    public Result findAllVillageByAreaCode(
            @ApiParam("县区六位行政区划代码,例如武侯区510107") @PathVariable String code){
        return service.findAllVillageByAreaCode(code);
    }
    //查询子元素
    @Cacheable("children")
    @GetMapping("/findAllChildren/{code}")
    @ApiOperation("查询下一级的区域")
    public Result findAllChildren(
            @ApiParam("区域代码,000000为查询全中国,四川省510000,成都市510100,武侯区510107,武侯区火车南站街道510107007") @PathVariable String code){
       return service.findAllChildren(code);
    }
    //查询成都东部新区的所有乡村区划
    @Cacheable("east")
    @GetMapping("/findAllEasternNewArea")
    @ApiOperation("查询东部新区所有的村、社区")
    public Result findAllEasternNewArea(){
        return service.findAllEasternNewArea();
    }


}
